package safari.model.member;

import java.sql.SQLException;
import java.util.List;

import safari.model.common.ListVO;
import safari.model.common.PagingBean;
import safari.model.message.IdAndPageVO;
import safari.model.transaction.TradeHistoryVO;

public class MemberServiceImpl implements MemberService {
	private MemberDao dao;
	private PagingBean pb1,pb2;
	public MemberServiceImpl(MemberDao dao){
		this.dao=dao;
	}
	
	@Override
	public int register(MemberVO mvo) throws SQLException {	
		return dao.register(mvo);	
	}

	@Override
	public int update(MemberVO mvo) throws SQLException {
		return dao.update(mvo);
	}

	@Override
	public int delete(String id) throws SQLException {
		// TODO Auto-generated method stub
		return dao.delete(id);
	}

	@Override
	public MemberVO login(MemberVO mvo) throws SQLException {
		return dao.login(mvo);
	}

	@Override
	public int findIdAndPassword(MemberVO mvo) throws SQLException {
		// TODO Auto-generated method stub
		return 0;
	}

	/**
	 * id 중복안되면 return 0 -> 회원가입 가능 
	 */
	@Override
	public int idCheck(String id) throws SQLException {
		return dao.idCheck(id);
	}

	@Override
	public MemberVO getInfo(String id) throws SQLException {
		return dao.getInfo(id);
	}

	@Override
	public int updateDelPic(MemberVO mvo) throws SQLException {
		// TODO Auto-generated method stub
		return dao.updateDelPic(mvo);
	}

	@Override
	public ListVO viewMySellTH(IdAndPageVO ipvo) throws SQLException {
		int pageNo=1;
		if(ipvo.getPage()!=0)
			pageNo=ipvo.getPage();
		ipvo.setPage(pageNo);
		List<TradeHistoryVO> sellTHList=dao.viewMySellTH(ipvo);
		pb1=new PagingBean(dao.getNumberOfSellTH(ipvo.getId()),pageNo);
		return new ListVO(sellTHList,pb1);
	}

	@Override
	public ListVO viewMyBuyTH(IdAndPageVO ipvo2) throws SQLException {
		int pageNo=1;
		if(ipvo2.getPage()!=0)
			pageNo=ipvo2.getPage();
		ipvo2.setPage(pageNo);
		List<TradeHistoryVO> buyTHList=dao.viewMyBuyTH(ipvo2);
		pb2=new PagingBean(dao.getNumberOfBuyTH(ipvo2.getId()),pageNo);
		return new ListVO(buyTHList,pb2);
	}

	@Override
	public int checkEmail(String email) throws SQLException {
		// TODO Auto-generated method stub
		return dao.checkEmail(email);
	}

}
